package com.qnbc.mystery.domain;

import java.util.*;

/**
 * @author gzj
 * @description 一番赏抽奖实体类
 * @date 2024/2/20 09:30
 */
public class MultiPrizeLottery {

    private List<ItemPrize> items;

    public MultiPrizeLottery(List<ItemPrize> items) {
        this.items = items;
    }

    public List<String> drawWinners(int numberOfPrizes) {
        List<String> winners = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < numberOfPrizes; i++) {
            double randomNumber = random.nextDouble();
            double cumulativeProbability = 0.0;
            for (ItemPrize item : items) {
                cumulativeProbability += item.getProbability();
                if (randomNumber <= cumulativeProbability) {
                    winners.add(item.getName());
                    item.decrementQuantity();
                    break;
                }
            }
        }
        return winners;
    }
}

